{extend name="$index_style_layout" /}

<!--SEO相关-->
{block name="head_title"}{$info.title}{/block}
{block name="head_keword"}{$info.keywords?:$info.title}  {$s_info.name} {/block}
{block name="head_description"}{:get_word(del_html($info['content']),200)}{/block}

{block name="body_content"}
<link rel="stylesheet" href="__STATIC__/zhidao/bencandy.css">
<style type="text/css">
pre{padding: 10px 15px;border: 1px solid #D1D7DC;    position: relative; margin: 10px 0; font-size: 12px; border-left: 6px solid #009688;  background-color: #f8f8f8; font-family: Courier New; max-width:250px;overflow-x:auto;}
</style>
<div class="bbsContainer">
	<style type="text/css">
	.category-head{width:100%;background:#F6F6F6;margin:10px 0 10px 0;padding:8px 0 5px 0;display: inline;white-space: nowrap;overflow-x:scroll;float:left;overflow-y:hidden}
	.category-head li{display:inline-block;height:30px;padding-left:15px;}
	</style>
	<ul class="category-head">
	{volist name="0|sort_config=###,'all'" id="rs"}
		   <li><a href="{:urls('content/index',['fid'=>$key])}" {eq name="$fid" value="$key"}style="color:blue;"{/eq}>{$rs}</a></li>
	{/volist}
	</ul>
	<div class="ContentBox" style="position: relative;">
		{eq name="$info.status" value="2"}<div style="position: absolute;left:120px;top:120px;filter: z-index: 1;"><img style="width:80px;opacity:0.1;filter:alpha(opacity=10);" src="__STATIC__/images/recom.png"></div>{/eq}

		<div class="title">{gt name="$info.list" value="$timestamp"}<span>顶</span>{/gt}<em>{$s_info.name}</em>{$info.title}
				{if $info.money>0}
				<i style='font-size:14px;color:#ffba23;'><i class='fa fa-fw fa-database'></i>{$info.money}</i>
				{/if}
		</div>

		<div class="thebase">
			<ul>
				<ol><a href="{:get_url('user',$info['uid'])}"><img src="{$info.uid|get_user_icon}" onerror="this.src='__STATIC__/images/nobody.gif'"></a><div><span onclick="sendmsg('{$info.uid|get_user_name}')">{$info.uid|get_user_name}</span><em>{$info.create_time|format_time=true}</em></div></ol>
				<li>
					<i class="si si-eye"></i><span>{$info.view}</span> 
					<label onclick="TopicAgree()"><i class="fa fa-thumbs-o-up"></i><span id="topic_agree">{$info.agree}</span></label>
					<!--操作菜单-->
					{include file="content/menu"}
				</li>
			</ul>
		</div>
		<div class="contentHtml">
			{$info.content}
			{volist name="$info.picurls" id="rs"}
				</br><img src="{$rs.picurl}"/>
			{/volist}
		</div>
		<div class="OtherAct">
			<!--<button type="button" onclick="layer.msg('请点击右上角进行分享！')"><i class="si si-share"></i> 分享</button>-->
			<button type="button" onclick="postcomment()"><i class="fa fa-commenting-o"></i>回答</button>			
			{notempty name=":plugins_config('givemoney')"}<button type="button"><i class="si si-present give-money" data-id="{$id}">打赏</i></button>{/notempty}
			<button type="button" onclick="gave_money({$id},0)">&yen;<!--赏钱--></button>
			<button type="button" onclick="add_fav({$id})"><li class="fa fa-fw fa-star-o"></li><!--收藏--></button>
		</div>




				{if $info.best_rid>0}
					<div class='show_best_reply'>
						<div class='best_reply_title'><i class='si si-badge'></i> 最佳答案<span>{$info.best_create_time|format_time="m-d H:i"}</span></div>
						<div class='best_reply_content'>
							{if $info.best_content}
								{$info.best_content}
							{else /}
								你来得晚啦，最佳答案内容可能已被问题发布者或回答用户删除！
							{/if}
						</div>
					</div>
				{/if}	







		<div class="showdsBox">
			<div class="h">共有<span>{$info.reward}</span>人打赏</div>
			<dl>
				<dt class="zhidao_topic_reword_wap001">
{qb:tag name="zhidao_topic_reword_wap001" js="zhidao_topic_reword_wap001" union="aid=id" rows="4" class="app\zhidao\model\Member@get_label"}
					<a href="{:get_url('user',$rs.uid)}"><span><img src="{$rs.icon}" onerror="this.src='__STATIC__/images/nobody.gif'"></span><em>{$rs.money}</em><label>元</label></a>
{/qb:tag}
				</dt>
				<dd onclick="show_more_reward({$id},0);$('.MoreInfoBox').fadeIn();">更多<i class="fa fa-angle-right"></i></dd>
			</dl>
		</div>
	</div>
	<ul class="topBoxs">		 
		<li class="atten"><a href="{:urls('content/add',['fid'=>$fid])}">发布问题</a></li>
	</ul>
	<div class="CommentBox">
		<ul class="head">
			<ol>全部回答</ol>
			<li>共 <span>{$info.replynum}</span> 条</li>
		</ul>
{qb:reply name="wapbbs_reply" rows="15"}
		<div class="ListComment">
		{volist name="listdb" id="rs"}
			<div class="lists">
				<ul>
					<ol><a {if is_dir(APP_PATH.'weibo')}href="{:url('weibo/api/weibo','uid='.$rs['uid'])}"{else /}href="{:get_url('user',$rs['uid'])}"{/if}><img src="{$rs.icon}" onerror="this.src='__STATIC__/images/nobody.gif'"></a></ol>
					<li>
						<div class="infos"><a href="javascript::" onclick="sendmsg('{$rs.username}')">{$rs.username}</a><em> {$rs.time}</em><span class="lou">{$i}楼</span></div>
						<div class="cnt replycontent">{$rs.content}</div>
						<!--{notempty name="rs.children"}{/notempty}-->
						<div class="replaycomment repalyinfs{$rs.id}">
							{volist name="rs.children" id="vs"}
							<dl>
								<dt><a href="javascript::" onclick="sendmsg('{$vs.username}')">{$vs.username}</a><em> {$vs.time}</em></dt>
								<dd class="replycontent">{$vs.content} 
								{if ($this->admin || $vs['uid']==$this->user['uid'])}<i onclick="delinfo({$aid},{$vs.id})" class="fa fa-trash-o"></i>
						
								{/if}</dd>
							</dl>
							 {/volist}
						</div>	
						<div class="showdsBox reply_reward" data-id="{$rs.id}">
							<!--
							<dl>
								<dt>
									<a href="#"><span><img src="__STATIC__/images/1.jpg"></span><em>7</em><label>元</label></a>
									<a href="#"><span><img src="__STATIC__/images/1.jpg"></span><em>7</em><label>元</label></a>
								</dt>
								<dd onclick="show_more_reward({$aid},{$rs.id});$('.MoreInfoBox').fadeIn();">更多<i class="fa fa-angle-right"></i></dd>
							</dl>
							-->
						</div>
						<div class="other">
							<i class="fa fa-yen" onclick="gave_money({$aid},{$rs.id})"> 赏钱</i>
							{notempty name=":plugins_config('givemoney')"}<i class="si si-present give-money" data-id="{$aid}" data-rid="{$rs.id}"> 打赏</i>{/notempty}
							<i class="fa fa-thumbs-o-up upnum replyAgree{$rs.id}" onclick="reply_agree({$rs.id})"> {$rs.agree}</i>
							<i class="fa fa-commenting-o" onclick="replyuser({$rs.id})"> 回复</i>
							{if ($this->admin || $info['uid']==$this->user['uid'])}
							<i onclick="delinfo({$aid},{$rs.id})" class="fa fa-trash-o"></i>
								{if !$info.best_rid}
									<a onclick="adoption_response({$info.id},{$rs.id})" href="javascript::"><i class="fa fa-fw fa-check-square-o"></i>采纳{$info.uid}</a>
								{/if}							
							{/if}
						</div>
					</li>
				</ul>
			</div>
		{/volist}
		</div>
	<script type="text/javascript">
	var posturl="{:fun('label@reply_api','posturl',$aid,$cfg_array)}";
	var pageurl="{:fun('label@reply_api','pageurl',$aid,$cfg_array)}";
	</script>
{/qb:reply}

	</div>
	<div class="ShowMoreBox">回答加载中……</div>

</div>
<script type="text/javascript">
//采纳
function adoption_response(id,rid){
	var url="{:urls('wxapp.post/adoption_response')}?id="+id+"&rid="+rid;
	$.get(url,function(res){
		console.log(res);
		if(res.code==0){
			layer.alert('已采纳该回答');	
			location.reload();
		}else if(res.code==1){
			layer.msg(res.msg);
			location.reload();
		}else{
			layer.msg("采纳失败:"+res.msg,{time:1500});
		}	
	});
}
function add_fav(id){
	var url="{:purl('fav/api/add')}?type={:config('system_dirname')}&id="+id;
	$.get(url,function(res){
		if(res.code==0){
			layer.msg('收藏成功');
		}else{
			layer.alert(res.msg);
		}
	})
}

jQuery(document).ready(function() {
	$(".contentHtml img").each(function(){
		$(this).click(function(){
			location.href=($(this).attr('src'));
		});
	});
	$(".CommentBox .replycontent img").each(function(){
		$(this).click(function(){
			location.href=($(this).attr('src'));
		});
		$(this).css({"max-width":'100%',});
	});

	bbslou();
})

//楼层
function bbslou(){
	var lou = 0;
	$(".CommentBox .lou").each(function(){
		lou++;
		$(this).html(lou+'楼')
	});
}

//发短消息
var haveSendMsg = false;
function sendmsg(name,ifsend){
	if(check_login()!=true) return ;
	if(ifsend==true){
		var contents = $(".sendmsgBox textarea").val();
		contents = contents.replace("\n","<br>");
		contents = contents.replace(" ","&nbsp;");	
		layer.closeAll();
		if(contents==''){
			layer.alert('内容不能为空!');
			return ;
		}
		if(haveSendMsg==true){
			layer.msg('请不要重复提交');
			return ;
		}
		haveSendMsg = true;
		layer.msg('正在发送消息,请稍候...');
        $.post("{:murl('member/wxapp.msg/add')}", {content:contents,touser:name}).success(function (res) {
			haveSendMsg = false;
            if(res.code==0){
				layer.closeAll(); //关闭所有层
				layer.msg('消息发送成功！');
				$(".sendmsgBox textarea").val('');
			}else{
				layer.alert(res.msg);
			}
		}).fail(function () {
			layer.open({title: '提示',content: '服务器发生错误'});
		});
	}else{
		layer.open({
		  type: 1,
		  title:'给 '+name+' 发私信',
		  area: ['90%'], //宽高，高参数忽略
		  content: '<ul class="replayBox sendmsgBox"><ol><textarea placeholder="请输入私信内容"></textarea></ol><li><span onclick="layer.closeAll();">取消</span><button onclick="sendmsg(\''+name+'\','+true+');">立即发送</button></li></ul>'
		});
	}
}

</script>
<div class="MoreInfoBox">
	<div class="BackBox" onclick="$('.MoreInfoBox').fadeOut();"></div>
	<div class="ShowinfoBox">
		<div class="h"><span>用户打赏列表</span></div>
		<div class="ListBox topic_reword_wapmore001">
{qb:tag name="topic_reword_wapmore001" js="topic_reword_wapmore001" union="aid=id,rid" rows="30" class="app\zhidao\model\Member@get_label"}
			<ul>
				<li class="icon"><a href="{:get_url('user',$rs['uid'])}"><img src="{$rs.icon}" onerror="this.src='__STATIC__/images/nobody.gif'"></a></li>
				<li class="info"><span>{$rs.username}</span><em>{$rs.time}</em></li>
				<li class="yen">打赏<span>{$rs.money}</span>元</li>
			</ul>
{/qb:tag}
		</div>
		<div class="closeBox"><span onclick="$('.MoreInfoBox').fadeOut();">关闭</span></div>
	</div>
</div>
	<!--评论的打赏列表-->
	<div style="display:none;" class="reply_reward_page1">
	{qb:tag name="reply_reward_page1" val="listdb" js="none" rows="3" union="aid,rid" class="app\zhidao\model\Member@get_label"}
		<dl>								
			<dt>
			{volist name="listdb" id="rs"}
			<a href="{:get_url('user',$rs['uid'])}"><span><img src="{$rs.icon}" onerror="this.src='__STATIC__/images/nobody.gif'"></span><em>{$rs.money}</em><label>元</label></a>
			{/volist}
			</dt>								
			<dd onclick="show_more_reward({$live_cfg.aid},{$live_cfg.rid});$('.MoreInfoBox').fadeIn();">更多<i class="fa fa-angle-right"></i></dd>
		</dl>
	{/qb:tag}
	</div>
<script type="text/javascript">
//显示更多打赏
function show_more_reward(aid,rid){
	var url = "{qb:url name='topic_reword_wapmore001' /}1&aid=" + aid + '&rid=' + rid;
	$.get(url,function(res){
		if(res.code==0){
			$(".topic_reword_wapmore001").html(res.data);			
		}else{
			layer.msg(res.msg);
		}	
	});
}

//评论默认显示的部分打赏
$(".reply_reward").each(function(){
	var that = $(this);
	var url = "{qb:url name='reply_reward_page1' /}1&aid={$id}&rid=" + $(this).data('id')
	$.get(url,function(res){
		if(res.code==0){
			that.html(res.data);
		}
	});
});
</script>

<script type="text/javascript">
//打赏积分
var sys_dirname = "{:config('system_dirname')}";
var give_money_url = "{:purl('givemoney/api/give','index')}";
var count_money_url = "{:purl('givemoney/api/count','index')}";
var getlist_money_url = "{:purl('givemoney/api/getlist','index')}";
$(document).ready(function () {
	$(".give-money").each(function(){
		var that = $(this);
		var id = that.data('id');
		var rid = typeof(that.data('rid'))=='undefined' ? 0 : that.data('rid');
		var cid = typeof(that.data('cid'))=='undefined' ? 0 : that.data('cid');
		
		that.each(function(){
			var obj = $(this);
			$.post(count_money_url,{'sysname':sys_dirname,'id':id,'rid':rid,'cid':cid},function(res){
				if(res.code==0){	//有人打赏过了
					obj.html(' '+res.data);
					obj.click(function(){
						layer.confirm('请问你是要打赏？还是要查看打赏的用户列表',{btn:['我要打赏','查看用户']},function(){
							layer.closeAll();
							putnum();
						},function(){
							getlist();
						});						
					});
				}else{	//还没人打赏
					obj.click(function(){						
						putnum();
					});					
				}
			});
		});
		
		//显示打赏用户
		var getlist = function(){
			layer.closeAll();
			layer.load(1);
			$.post(getlist_money_url,{'sysname':sys_dirname,'id':id,'rid':rid,'cid':cid},function(res){
				layer.closeAll();
				if(res.code==0){
					var str = '';
					res.data.forEach(function(rs){
						str += '<div style="padding:5px;"><span style="color:blue;">' + rs.username + '</span> 打赏积分: ' + rs.money + ' 个 <span style="color:#666;">['+rs.create_time+']</span></div>';
					});
					layer.open({
					  title:'打赏用户列表',
					  type: 1,
					  area: '98%',
					  content: '<div style="padding:15px;">' + str + '</div>',
					});
				}else{
					layer.alert(res.msg);
				}
			}).fail(function(){layer.closeAll();layer.alert('页面出错了!')});
		}
		
		//打赏输入积分个数
		var putnum = function(){
			layer.prompt({
				  formType: 0,
				  value: '3',
				  title: '请输入要打赏的积分个数',
				  //area: ['100px', '20px'] //formType:2 自定义文本域宽高
				}, function(value, index, elem){
					layer.close(index);
					postdata(value);
				}
			);
		};
		
		//打赏提交数据
		var postdata = function(num){			
			layer.load(1);
			$.post(give_money_url,{'sysname':sys_dirname,'money':num,'id':id,'rid':rid,'cid':cid,'about':''},function(res){
				layer.closeAll();
				if(res.code==0){
					layer.msg('谢谢你的打赏!');
				}else{
					layer.alert(res.msg);
				}
			}).fail(function(){layer.closeAll();layer.alert('页面出错了!')});
		}		
	});
});
</script>


<script type="text/javascript">

//修改信息
function editinfo(aid,id){
	var url;
	if(id>0){
		url="{:urls('reply/edit')}?id="+id;
	}else{
		url="{:urls('content/edit')}?id="+aid;
	}
	location.href = url;
}

//删除信息
function delinfo(aid,id){
	var url;
	if(id>0){
		url="{:urls('wxapp.reply/delete')}?id="+id;
	}else{
		url="{:urls('wxapp.post/delete')}?id="+aid;
	}
	$.get(url,function(res){
		if(res.code==0){
			layer.msg("删除成功！",{time:500});
			if(id==0){
				location.href="{:urls('index/index')}";
			}else{
				location.reload();
			}
		}else{
			layer.msg("删除失败:"+res.msg,{time:2500});
		}	
	});
}

//主题点赞
function TopicAgree(){	
	$.get("{:urls('wxapp.post/agree',['id'=>$id])}?"+Math.random(),function(res){
		if(res.code==0){
			var num =  $('#topic_agree').html();
			num++;
			$('#topic_agree').html(num);
			layer.msg("点赞成功！",{time:500});
		}else{
			layer.msg("点赞失败:"+res.msg,{time:2500});
		}	
	});
}

//回复点赞
function reply_agree(id){
	$.get("{:urls('wxapp.reply/agree')}?id=" + id + "&" + Math.random(),function(res){
		if(res.code==0){
			var num =  $('.replyAgree'+id).html();
			num++;
			$('.replyAgree'+id).html(num);
			layer.msg("点赞成功！",{time:500});
		}else{
			layer.msg("点赞失败:"+res.msg,{time:2500});
		}	
	});
}

//打赏
function gave_money(aid,rid){
	layer.open({
	  type: 1,
	  title:'我要打赏',
	  area: ['300'], //宽高，高参数忽略
	  content: '<ul class="replayBox"><ol><input class="gavemoney" type="number" step="0.01"  min="0.3" placeholder="请输入打赏金额" />单位:元</ol><li><button onclick="post_mopey('+aid+','+rid+');">确定</button><span onclick="layer.closeAll();">取消</span></li></ul>'
	});
}
function post_mopey(aid,rid){
	var money = $('.replayBox .gavemoney').val();
	money = parseFloat(money).toFixed(2);
	if(isNaN(money)){
		layer.msg('请输入正确的金额',{time:800});
		return ;
	}else if(money<0.3){
		layer.msg('打赏金额不能小于0.3元',{time:800});
		return ;
	}

	$.get("{:urls('wxapp.post/reward')}?id=" + aid + '&rid=' + rid + '&money=' + money + '&' + Math.random(),function(res){
		if(res.code==0){
			layer.closeAll(); //关闭所有层
			layer.msg(res.msg);
		}else if(res.code==2){
			layer.msg('你的余额只有'+res.data.money+',请先充值',{time:1000});
			setTimeout(function(){
				callpay();
			},1000);
		}else{
			layer.alert(res.msg);
		}
	});
	
}

function check_login(){
	if("{$userdb.uid}"==""){
		layer.confirm('你还没登录,你确认要登录吗？', {
            btn : [ '确定', '取消' ]
        }, function(index) {
            location.href="{:get_url('login')}";
        });		
	}else{
		return true;
	}
}

//对问题提交回答
function postcomment(){
	if(check_login()!=true) return ;
	layer.open({
	  type: 1,
	  title:'我要回答',
	  area: ['90%'], //宽高，高参数忽略
	  content: '<ul class="replayBox"><ol><textarea placeholder="请输入您的回答，好内容帮助更多人..."></textarea></ol><li><button onclick="postcomment1();">确定</button><span onclick="layer.closeAll();">取消</span></li></ul>'
	});
}

//提交回复信息
var havepost = false;
function postcomment1(pid){
	var url = posturl;
	if(pid>0){
		url += "?pid="+pid;
	}
	var contents = $('.replayBox textarea').val();			
	if(contents==''){
		layer.msg("请输入回答内容！",{time:1500});
	}else{
		if(havepost==true){
			layer.msg('请不要重复提交');
			return ;
		}
		havepost = true;
		$.post(
			url,
			{content:contents},
			function(res,status){
				havepost = false;
				if(res.code==0){
					if(pid>0){
						$('.repalyinfs'+pid).html(res.data);
					}else{
						$('.ListComment').html(res.data);
						//$('.ShowMoreComment').fadeIn();
					}
					layer.closeAll(); //关闭所有层
					layer.msg("发表成功！",{time:1500});
					//HiddenShowMoreComment();
				}else{
					layer.msg("评论发表失败:"+res.msg,{time:1500});
				}
			}
		);				
	}
}

//引用回复
function replyuser(id){
	if(check_login()!=true) return ;
	layer.open({
	  type: 1,
	  title:'给TA回复',
	  area: ['90%'], //宽高，高参数忽略
	  content: '<ul class="replayBox"><ol><textarea placeholder="请输入回复内容"></textarea></ol><li><button onclick="postcomment1(' + id + ');">确定</button><span onclick="layer.closeAll();">取消</span></li></ul>',
	});
}

//显示分页
var page=1;
var totalpage = 1;
var check_showMore=1;
$('.ShowMoreBox').hide();
function howMoreComment(){
	page++;
	check_showMore=0;
	$('.ShowMoreBox').fadeIn();
	$.get(pageurl + "?page="+page+"&"+Math.random(),function(res){
		$('.ShowMoreArtic').fadeOut();
		if(res.code==0){
			if(res.data==''){
				if(res.paginate.total==0){
					//layer.msg("还没有评论",{time:500});
				}else{
					layer.msg("没有更多内容了！",{time:500});
				}				
				$('.ShowMoreBox').hide();
			}else{
				$('.ListComment').append(res.data);
				check_showMore=1;
				bbslou();
			}
		}else{
			layer.msg(res.msg,{time:2500});
		}
	});
}

$(document).ready(function () {
	$(window).scroll(function () {
		var scroll_Height=$(window).scrollTop();
		if($('body').height()-scroll_Height<1300 && check_showMore==1){
			howMoreComment();
		}
	});
});





//微信充值
    var wxpay = {};
	//调用微信JS api 支付
	function jsApiCall()
	{
		WeixinJSBridge.invoke(
			'getBrandWCPayRequest',
			wxpay,
			function(res){
				WeixinJSBridge.log(res.err_msg);
				//alert(res.err_code+res.err_desc+res.err_msg);
				if(res.err_msg=='get_brand_wcpay_request:ok'){
					layer.msg('充值成功,请现在可以打赏了!');
				}
				//if(res.err_msg=='get_brand_wcpay_request:cancel')window.location.href="https://x1.php168.com/index/pay/index/banktype/weixin/action/pay_end_return.html?ispay=0&numcode=6e22a6621d";
			}
		);
	}

	function callpay()
	{
		var money = $('.replayBox .gavemoney').val();
			money = parseFloat(money).toFixed(2);
		if(isNaN(money)){
			money = 0.3;
		}
		$.get("{:iurl('index/wxapp.pay/index')}" + '?type=mp&title=打赏充值&money=' + money + '&' + Math.random(),function(res){
			if(res.code==0){
				wxpay = eval("("+res.data.json+")");
				if (typeof WeixinJSBridge == "undefined"){
					if( document.addEventListener ){
						document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
					}else if (document.attachEvent){
						document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
						document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
					}
				}else{
					jsApiCall();
				}


			}else{
				layer.alert(res.msg);
			}
		});
	}
//callpay();
</script>

<!-- 微动态自动收录用户感兴趣的主题,时间60代表用户停留60秒将自动收藏 -->
{:fun('sns@fav',$info,60,'系统帮你订阅了本主题,下次本主题有回复,将会通知你')}

<!-- 微信分享 -->
{include file="index@share"/}

{/block}